package com.rp.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.rp.common.utils.RpUtil;
import com.rp.system.po.User;

public class UserTag extends TagSupport {
	
	private static final long serialVersionUID = -533185446095541004L;
	
	private String property = "";
	
	@Override
	public int doEndTag() throws JspException {
		User user = User.getCurrentUser();
		JspWriter out = pageContext.getOut();
		try{
			if(RpUtil.isNullOrEmpty(user)){
				out.print("<span id='"+id+"' style='color: red;'>No login user!</span>");
			}else{
				if(property.equals("realname")){
					out.print(user.getRealname());
				}else if(property.equals("username")){
					out.print(user.getUsername());
				}else if(property.equals("id")){
					out.print(user.getId());
				}else if(property.equals("headImg")){
					out.print(user.getHeadImg());
				}else if(property.equals("roleName")){
					out.print(user.getRoleName());
				}else if(property.equals("roleId")){
					out.print(user.getRoleId());
				}
			}
		}catch (IOException e) {
			throw new JspException(e);
		}
		return EVAL_PAGE;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}
	
}
